package org.lhh.server.controller;

import org.lhh.server.annotation.LogCatch;
import org.lhh.server.annotation.UserAuth;
import org.lhh.server.common.api.JSONResult;
import org.lhh.server.core.codec.slave.SlaveServerCodec;
import org.lhh.server.service.ISlaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/slave")
public class SlaveController {

    @Autowired
    private ISlaveService slaveService;


    @UserAuth
    @LogCatch(value = "子服务器-列表")
    @GetMapping("/list")
    public JSONResult list() {
        return slaveService.list();
    }

    @UserAuth
    @LogCatch(value = "子服务器-保存")
    @RequestMapping(method = RequestMethod.PUT, value = "/save")
    public JSONResult save(@RequestBody SlaveServerCodec slaveServerCodec) {
        slaveService.saveSlaveServer(slaveServerCodec);
        return JSONResult.ok();
    }


    @UserAuth
    @LogCatch(value = "子服务器-删除")
    @RequestMapping(method = RequestMethod.DELETE, value = "/delete/{id}")
    public JSONResult list(@PathVariable Long id ) {
        slaveService.remove(id);
        return JSONResult.ok();
    }

    @UserAuth
    @LogCatch(value = "子服务器-测试")
    @RequestMapping(method = RequestMethod.PUT, value = "/test")
    public JSONResult test(@RequestBody SlaveServerCodec slaveServerCodec) {
        return slaveService.test(slaveServerCodec);
    }

}
